package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class ADD2ARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject.length < 2) || (paramArrayOfObject.length > 3))
      return Primitive.ERROR_VALUE;
    Object localObject1 = paramArrayOfObject[0];
    if (!(localObject1 instanceof FArray))
      return Primitive.ERROR_VALUE;
    Object localObject2 = paramArrayOfObject[1];
    int i = 0;
    if (paramArrayOfObject.length == 3)
    {
      Object localObject3 = paramArrayOfObject[2];
      if (localObject3 instanceof Integer)
        i = Integer.parseInt(localObject3.toString());
    }
    return addElement((FArray)localObject1, localObject2, i);
  }

  private FArray addElement(FArray paramFArray, Object paramObject, int paramInt)
  {
    FArray localFArray1 = new FArray();
    if (paramInt < 1)
      paramInt = 1;
    if (paramObject instanceof FArray)
    {
      FArray localFArray2 = (FArray)paramObject;
      for (int j = 0; j < paramInt - 1; ++j)
        localFArray1.add(paramFArray.elementAt(j));
      for (j = 0; j < localFArray2.length(); ++j)
        localFArray1.add(localFArray2.elementAt(j));
      j = paramInt - 1;
      while (true)
      {
        if (j >= paramFArray.length())
          break label190;
        localFArray1.add(paramFArray.elementAt(j));
        ++j;
      }
    }
    for (int i = 0; i < paramInt - 1; ++i)
      localFArray1.add(paramFArray.elementAt(i));
    localFArray1.add(paramObject);
    for (i = paramInt - 1; i < paramFArray.length(); ++i)
      localFArray1.add(paramFArray.elementAt(i));
    label190: return localFArray1;
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "ADDARRAY(array, insertArray, start):在数组第start个位置插入insertArray中的所有元素，再返回该数组。\n示例：\nADDARRAY([3, 4, 1, 5, 7], [23, 43, 22], 3)返回[3, 4, 23, 43, 22, 1, 5, 7].\nADDARRAY([3, 4, 1, 5, 7], \"测试\", 3)返回[3, 4, \"测试\", 1, 5, 7].\n注意：如果start为小于1的数或者不写start参数，则默认从数组的第一位开始插入数组元素。";
  }

  public String getEN()
  {
    return "";
  }
}